import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Properties;

import HillClimbing.HillClimbing.IPropertiesObj;



public class PropertiesObj implements IPropertiesObj 
{	
	double[] params;
	
	private static PropertiesObj _currentProperties;
	
	public PropertiesObj()
	{
		Properties props = new Properties();
		try
		{
			props.load(new FileInputStream("D:\\dev\\Java\\computational-human-genetics-project\\properties"));
		}
		catch(Exception e)
		{
			System.out.println(e.getMessage());
		}
		
		this.params = new double[2];
		
		setClusterNumber((int)Double.parseDouble(props.getProperty("CLUSTER_NUMBER", "200")));
		this.params[1] = Double.MAX_VALUE;
	}
	
	public static PropertiesObj GetPropertiesObject()
	{
		if ( _currentProperties == null)
			_currentProperties = new PropertiesObj();
		return _currentProperties;
	}
	
	public PropertiesObj(double[] params)
	{
		this.setParams(params);
	}
	public void save(double score)
	{
		Date dt = new Date();
		save(dt.toString().replace(":", "_"), "score: " + score);
	}
	
	public void save(int index, double score)
	{
		save(index + "", "score: " + score);
	}
	
	public void save(String index, String comment)
	{
		Properties props = new Properties();

		String[] keys = new String[] { "CLUSTER_NUMBER" ,"SCORE"};
		for(int i=0; i< keys.length; i++)
		{
			props.setProperty(keys[i], this.params[i] + "");
		}
		try
		{
			props.store(new FileOutputStream("D:\\dev\\Java\\computational-human-genetics-project\\properties_" + index), comment);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public void setParams(double[] params)
	{
		this.params = params;
//		this.save("temp", "this is only the temp props");
	}
	
	public double[] getParams()
	{
		return this.params;
	}
	
	public void setClusterNumber(double ClusterNumber) 
	{
		this.params[0] = ClusterNumber;
	}
	public int getClusterNumber() 
	{
		return (int)this.params[0];
	}
	
	@Override
	public String toString() 
	{
		return "Clusters Number: " + this.params[0];
	}
	
	public static void setPropertiesObject(PropertiesObj m_props) {
		_currentProperties = m_props;
	}
	

	public void setScore(double finalScore) {
		this.params[1] = finalScore;
		
	}
}
